﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Social.Components.Tester.Win8.Views.CachePage"
    DataContext="{Binding Feeds, Source={StaticResource Locator}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Social.Components.Tester.Win8.Views"
    xmlns:common="using:Social.Components.Tester.Win8.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:it="using:ImageTools.Controls"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">My Application</x:String>
        <it:ImageConverter x:Key="ImageConverter"/>

        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"/>

        <DataTemplate x:Key="StoreFrontTileTemplate">
            <Grid HorizontalAlignment="Left" Background="WhiteSmoke"  Height="180" Width="400">
                <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Horizontal">
                        <!--<Image Source="{Binding HeadImg}" Height="80" Width="80" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="Fill" Margin="15,15,0,0"/>-->
                        <it:ImageExt Source="{Binding HeadImg, Converter={StaticResource ImageConverter}}" Height="80" Width="80" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="Fill" Margin="15,15,0,0"/>
                        <Grid>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="{Binding UserName}" FontSize="20" Margin="5,20,0,0" Foreground="Blue" VerticalAlignment="Top"/>
                                <TextBlock Text="{Binding Date}" FontSize="15" Margin="5,30,0,0" Foreground="Red" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                    <TextBlock Text="{Binding State}" Foreground="Black" Width="350"  Height="100" Margin="15,5,0,0"  TextWrapping="Wrap" HorizontalAlignment="Left"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <GridView ItemTemplate="{StaticResource StoreFrontTileTemplate}"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="116,136,116,46"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}">
        </GridView>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="新鲜事" Style="{StaticResource PageHeaderTextStyle}"/>
            <Button Content="Load" Grid.Column="1" HorizontalAlignment="Left" Height="58" Margin="240,58,0,0" VerticalAlignment="Top" Width="116" Command="{Binding Command}"/>
        </Grid>
        <ProgressRing  Grid.Row="1" Height="80" Width="80" HorizontalAlignment="Center"  VerticalAlignment="Center"  IsActive ="{Binding IsChecked}"/>
        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
